package com.cskaoyan.last.print;

/**
 * 打印类
 *
 * @author 徐文祥
 * @since 2023/05/09 21:34
 */
public class Printer {
    private int index = 1;

    public synchronized void print(int i) {
        if (index % 3 == 0) {
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.print(i);
        index++;
        notifyAll();

    }

    public synchronized void print(char c) {
        if (index % 3 != 0) {

            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.print(c);
        index++;
        notifyAll();

    }
}
